package com.tkjt.pms.modules.performances.controller;

import com.tkjt.pms.modules.performances.model.reportrowList.ReportrowListModel;
import com.tkjt.pms.modules.performances.model.vos.IndexValueVo;
import com.tkjt.pms.modules.performances.service.PerformancesService;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/performances")
public class PerformancesController {

    private final PerformancesService performancesService;

    @Autowired
    public PerformancesController(PerformancesService performancesService) {
        this.performancesService = performancesService;
    }

    @GetMapping("/myReportrowList")
    public Result getMyReportrowList(HttpServletRequest request) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if(loginUser==null) {
            return Result.error("用户非法！");
        }
        ReportrowListModel model=performancesService.getMyReportrowList(loginUser,request);
//        JSONObject result=JSONObject.fromObject(model);
//        log.info(result.toString());
        return Result.ok(model);
    }

    @GetMapping("/detailDatagrid")
    public Result detailDatagrid(HttpServletRequest request) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if(loginUser==null) {
            return Result.error("用户非法！");
        }
        List<IndexValueVo> list=performancesService.getDetailDatagrid(loginUser,request);
//        JSONObject result=new JSONObject();
//        result.put("list",list);
//        log.info(result.toString());
        return Result.ok(list);
    }

}
